<form class="form-horizontal" role="form" action="{:url('doadd')}" method="POST"
id="collectform">
	{empty name="user"}
		<input type="hidden" name="uid" id="uid">
		<div class="form-group">
			<label for="firstname" class="col-sm-2 control-label">手机号码</label>
			<div class="col-sm-6">
				<div class="input-group">
					<input type="text" class="form-control" id="phone" placeholder="请输入手机号码" >
					<span class="input-group-addon msg-box"></span>
				</div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label">姓名</label>
			<div class="col-sm-6">
				<span class="form-control" id="name"></span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label">身份证</label>
			<div class="col-sm-6">
				<span class="form-control" id="idcard"></span>
			</div>
		</div>
	{else/}
		<input type="hidden" name="uid" id="uid" value="{$user.id}">
		<div class="form-group">
			<label class="col-sm-2 control-label">姓名</label>
			<div class="col-sm-6">
				<sapn class="form-control" >{$user.name}</sapn>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label">身份证</label>
			<div class="col-sm-6">
				<sapn class="form-control" >{$user.idcard}</sapn>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label">手机</label>
			<div class="col-sm-6">
				<sapn class="form-control" >{$user.phone}</sapn>
			</div>
		</div>
	{/empty}
	<div class="form-group">
		<label for="lastname" class="col-sm-2 control-label">金额</label>
		<div class="col-sm-6">
			<div class="input-group">
				<input type="text" class="form-control" id="amount" name="amount" placeholder="金额">
				<span class="input-group-addon msg-box"></span>
			</div>
		</div>
	</div>
	<div class="form-group">
		<label for="lastname" class="col-sm-2 control-label">截止时间</label>
		<div class="col-sm-6">
			<input type="date" class="form-control" id="deadline" name="deadline" placeholder="形如2017/08/03" value="{:date('Y-m-d')}">
		</div>
	</div>
	<div class="form-group">
		<label for="lastname" class="col-sm-2 control-label">期数</label>
		<div class="col-sm-6">
			<input type="number" class="form-control" id="periods" name="periods">
		</div>
	</div>
	<div class="form-group">
		<div class="col-sm-offset-2 col-sm-6">
		<input type="submit" class="btn btn-info" value="提交">
			<!-- <button type="submit" class="btn btn-info">提交</button> -->
		</div>
	</div>
</form>
<script>
	$(function(){
		$('#phone').blur(function(e){
			$this=$(e.target);
			$msg_box=$this.siblings('.msg-box');
			var phone = $this.val();
			if(!phone){
				$msg_box.html("<span class='text-danger'><i class='fa fa-close'></i> 请填入手机号</span>");
			}else{
				$.ajax({
					url:'verify',
					data:{"phone":phone},
					async:"false",
					dataType:"json",
					type:"post",
					success:function(res){	
						if(res.res_code==0){
							var data=res.res_data;
							$("#uid").val(data.id);
							$("#name").text(data.name);
							$("#idcard").text(data.idcard);
							$msg_box.html("<span class='text-success'><i class='fa fa-check'></i></span>");
						}else{
							$msg_box.html("<span class='text-danger'><i class='fa fa-close'></i> "+res.res_msg+"</span>");
						}
					},
					error:function(){
						alert("系统错误");
					}
				});		
			}
		})
		$('#amount').blur(function(e){
			$this=$(e.target);
			$msg_box=$this.siblings('.msg-box');
			var amount = $this.val();
			if(!amount)
				$msg_box.html("<span class='text-danger'><i class='fa fa-close'></i> 请填写金额</span>");
			else if(isNaN(amount)||amount<=0)
				$msg_box.html("<span class='text-danger'><i class='fa fa-close'></i> 格式错误</span>");
			else $msg_box.html("<span class='text-success'><i class='fa fa-check'></i></span>");
		})
		$('#collectform').submit(function(){
			var uid=$('#uid').val();
			var amount=$('#amount').val();
			if(!uid||isNaN(amount)||amount<=0)
				return false;

		})
	})
</script>